(function() {

var Book = Class.extend({
	init: function() {
		this.list = [];
	},
	getList: function(vcode) {
		if (this.list.length == 0) {
			this._loadList(vcode);
		}
		return this.list;
	},
	getBook: function(vcode, bcode) {
		if (this.list.length == 0) {
			this._loadList(vcode);
		}
		return this._findBook(vcode, bcode);
	},
	
	_loadList: function(vcode) {
		var self = this;
		$.ajax({
			url: "/data/books",
			async: false,
			data: {"vcode": vcode},
			success: function(data) {
				console.log(data);
				var list = $.parseJSON(data);
				console.log(list);
				list.pop();
				self.list = list;
			}
		});
	},
	_findBook: function(vcode, bcode) {
		for (var i = 0 ; i < this.list.length ; i++) {
			if (this.list[i].bcode == bcode) {
				return this.list[i];
			}
		}
		return null;
	}
});
	
holybible.model.Book = {
	instance: new Book(),
	getInstance: function() {
		if (!this.instance) {
			this.instance = new Book();
		}
		return this.instance;
	}
};


})();